//
//  ZKingNavigationBar.m
//  CustomNavigationBar
//
//  Created by zkingsoft on 15/12/29.
//  Copyright (c) 2015年 zkingsoft. All rights reserved.
//

#import "ZKingNavigationBar.h"

#import "NavigationBarButtonItem.h"
#import "UINavigationItem+CustomBarButtonItem.h"

@implementation ZKingNavigationBar


- (void)drawRect:(CGRect)rect {
    // 设置navigationbar的背景图片 nav_bg_image.png
    [[UIImage imageNamed:@"bg_clear.png"] drawInRect:rect];
    
    UIImage *image = [UIImage imageNamed:@"bg_clear.png"];
    [self setBackgroundImage:image forBarMetrics:UIBarMetricsCompact];
}

- (void)setNeedsLayout{
    [super setNeedsLayout];
    
    self.barStyle = self.statusBarStytle?[self.statusBarStytle integerValue]:DEFAULTSTATUSBARSTYTLE;
    
    // 创建一个黑色的状态栏背景
    UIView *statusBarView = [self viewWithTag:10000];
    if (!statusBarView) {
        statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, KWIDTH, 20)];
        statusBarView.backgroundColor = [UIColor clearColor];
        [self addSubview:statusBarView];
    }
    
    // 防止在ios7中navbar和statusbar 不悬浮的作用
    self.translucent = NO;
    
    self.tintColor = [UIColor clearColor];
}


// 设置状态栏颜色的set方法
- (void)setStatusBarColor:(UIColor *)statusBarColor{
    self.statusBarColor = statusBarColor;
    UIView *statusBarView = [self viewWithTag:10000];
    if (!statusBarView && statusBarColor) {
        [self setNeedsLayout];
    }
}


// 设置状态栏状态的set方法
- (void)setSystemBarStytle:(UIBarStyle)systemBarStytle{
    self.statusBarStytle = [NSNumber numberWithInteger:self.systemBarStytle];
    
    [self setNeedsLayout];
}


// 设置状态栏为黑底白字
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden{
    return NO;
}


@end






